<?php

namespace app\home\controller;

use app\home\model\MerchantModel;
use think\facade\Session;


class Login
{


    public function login(){




        $data=input('');
        if(request()->isGet() && request()->isAjax()) {
            $admin = MerchantModel::Login($data);
            if (!empty($admin)) {
                return $this->result($admin);
            } else {
                return $this->error();
            }
        }

        return View();
    }

    /***
     * 退出登录
     */
    public function logout(){


        Session::delete('member_name');
        Session::delete('member_id');

        return redirect((string)url('Login/login')->build());
    }


    public function success($data=[],$code=200,$msg="success"){

        $msg=[
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];
        return json($msg,200);
    }


    public function error($msg="error",$data=[],$code=400){

        $msg=[
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];
        return json($msg,400);
    }

    public function result($data=[]){


        return json($data);
    }

}